<div class="form-group-title">图片存储设置</div>

<div class="form-group">
    <label class="col-lg control-label">远程附件</label>
    <div class="col-sm-9 col-xs-12">
        <label class="radio-inline">
            <input type="radio" name="data[remote][type]" value="0" onclick="$('.remote-qiniu').hide();$('.remote-alioss').hide();$('.remote-ftp').hide();$('.remote-close').show();$('.remote-cos').hide();" {if empty($accountSettings['remote']['type']) || $accountSettings['remote']['type'] == '0'} checked="checked" {/if}> 关闭
        </label>
        <label class="radio-inline">
            <input type="radio" name="data[remote][type]" value="2" onclick="$('.remote-qiniu').hide();$('.remote-alioss').show();$('.remote-ftp').hide();$('.remote-close').hide();$('.remote-cos').hide();" {if !empty($accountSettings['remote']['type']) && $accountSettings['remote']['type'] == '2'} checked="checked" {/if}> 阿里云OSS
            <span class="label label-success">推荐，快速稳定</span>
        </label>
        <label class="radio-inline">
            <input type="radio" name="data[remote][type]" value="3" onclick="$('.remote-qiniu').show();$('.remote-alioss').hide();$('.remote-ftp').hide();$('.remote-close').hide();$('.remote-cos').hide();" {if !empty($accountSettings['remote']['type']) && $accountSettings['remote']['type'] == '3'} checked="checked" {/if}> 七牛云存储
            <span class="label label-success">推荐，快速稳定</span>
        </label>
        <label class="radio-inline">
            <input type="radio" name="data[remote][type]" value="4" onclick="$('.remote-qiniu').hide();$('.remote-alioss').hide();$('.remote-ftp').hide();$('.remote-close').hide();$('.remote-cos').show();" {if !empty($accountSettings['remote']['type']) && $accountSettings['remote']['type'] == '4'} checked="checked" {/if}> 腾讯云存储
            <span class="label label-success">推荐，快速稳定</span>
        </label>
    </div>
</div>

<!-- 阿里云 start -->
<div class="remote-alioss" {if empty($accountSettings['remote']['type']) || $accountSettings['remote']['type'] != '2'} style="display:none;" {/if}>
<div style="padding-left: 60px;">
    <div class="alert alert-warning">
        启用阿里oss后，请把/attachment目录（不包括此目录）下的子文件及子目录上传至阿里云oss<br>
        使用内网上传请一定注意OSS地域必须与ECS服务器的地域相同（例如:杭州）<br>
        <ul class="link-list">
            <p style="line-height: 2rem;"><a>相关工具：</a></p>
            <p style="line-height: 2rem;"><a target="_blank" href="http://market.aliyun.com/products/53690006/cmgj000281.html?spm=5176.383663.9.22.faitxp" class="product-grey-font" data-spm-anchor-id="5176.383663.9.22">官方推荐OSS客户端工具（Windows版）</a></p>
            <p style="line-height: 2rem;"><a target="_blank" href="http://market.aliyun.com/products/53690006/cmgj000282.html?spm=5176.383663.9.23.faitxp" class="product-grey-font" data-spm-anchor-id="5176.383663.9.23">官方推荐OSS客户端工具（Mac版）</a></p>
            <p style="line-height: 2rem;"><a target="_blank" href="http://market.aliyun.com/products/53690006/cmgj000208.html?spm=5176.383663.9.24.faitxp" class="product-grey-font" data-spm-anchor-id="5176.383663.9.24">Ftp4ossServer（OSS的FTP云工具）</a></p>
        </ul>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">Access Key ID</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][alioss][key]" class="form-control" value="{$accountSettings['remote']['alioss']['key']}" placeholder=""/>
        <span class="help-block">
            Access Key ID是您访问阿里云API的密钥，具有该账户完全的权限，请您妥善保管。
        </span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">Access Key Secret</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][alioss][secret]" class="form-control encrypt" value="{$accountSettings['remote']['alioss']['secret']}" placeholder=""/>
        <span class="help-block">
            Access Key Secret是您访问阿里云API的密钥，具有该账户完全的权限，请您妥善保管。(填写完Access Key ID 和 Access Key Secret 后请选择bucket)
        </span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">内网上传</label>
    <div class="col-sm-9">
        <input type="radio" name="data[remote][alioss][internal]" id="type-12" value="1" {if $accountSettings['remote']['alioss']['internal'] == 1}checked{/if}>
        <label class="radio-inline" for="type-12">
            是
        </label>
        <input type="radio" name="data[remote][alioss][internal]" id="type-13" value="0" {if $accountSettings['remote']['alioss']['internal'] != 1}checked{/if}>
        <label class="radio-inline" for="type-13">
            否
        </label>
        <span class="help-block">
            如果此站点使用的是阿里云ecs服务器，并且服务器与bucket在同一地区（如：同在华北一区），您可以选择通过内网上传的方式上传附件，以加快上传速度、节省带宽。
        </span>
    </div>
</div>
<div class="form-group" id="bucket"> <!--{if empty($accountSettings['remote']['alioss']['key'])}style="display: none;{/if}"-->
    <label class="col-sm-2 control-label">Bucket选择</label>
    <div class="col-sm-9">
        <select name="data[remote][alioss][bucket]" class="form-control"></select>
        <span class="help-block">
            完善Access Key ID和Access Key Secret资料后可以选择存在的Bucket(请保证bucket为可公共读取的)，否则请手动输入。
        </span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">自定义URL</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][alioss][url]" class="form-control" {if !strexists($accountSettings['remote']['alioss']['url'],'aliyuncs.com')}value="{$accountSettings['remote']['alioss']['url']}"{/if} placeholder="默认URL不需要填写"/>
        <span class="help-block">
            阿里云oss支持用户自定义访问域名，如果自定义了URL则用自定义的URL，如果未自定义，则用系统生成出来的URL。注：自定义url开头加http://或https://结尾不加 ‘/’例：http://abc.com
        </span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label"></label>
    <div class="col-sm-9">
        <button name="button" type="button" class="btn btn-info js-checkremoteoss" value="check">测试配置（无需保存）</button>
        {if !empty($local_attachment)}
        <a name="button" class="btn btn-info one-key">一键上传</a>
        {/if}
    </div>
</div>
</div>
<!-- 阿里云 end -->

<!-- 七牛云 start -->
<div class="remote-qiniu" {if empty($accountSettings['remote']['type']) || $accountSettings['remote']['type'] != '3'} style="display:none;" {/if}>
<div style="padding-left: 60px;">
    <div class="alert alert-info">
        启用七牛云存储后，请把/attachment目录（不包括此目录）下的子文件及子目录上传至七牛云存储, 相关工具：<br>
        <ul class="link-list">
            <p><a target="_blank" href="https://portal.qiniu.com/signin" class="product-grey-font">七牛云存储</a></p>
        </ul>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">Accesskey</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][qiniu][accesskey]" class="form-control" value="{$accountSettings['remote']['qiniu']['accesskey']}" placeholder=""/>
        <span class="help-block">用于签名的公钥</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">Secretkey</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][qiniu][secretkey]" class="form-control encrypt" value="{$accountSettings['remote']['qiniu']['secretkey']}" placeholder=""/>
        <span class="help-block">用于签名的私钥</span>
    </div>
</div>
<div class="form-group" id="data[remote][qiniu]bucket">
    <label class="col-sm-2 control-label">Bucket</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][qiniu][bucket]" class="form-control" value="{$accountSettings['remote']['qiniu']['bucket']}" placeholder=""/>
        <span class="help-block">请保证bucket为可公共读取的</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">Url</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][qiniu][url]" class="form-control" value="{$accountSettings['remote']['qiniu']['url']}" placeholder=""/>
        <span class="help-block">七牛支持用户自定义访问域名。注：url开头加http://或https://结尾不加 ‘/’例：http://abc.com</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label"></label>
    <div class="">
        <button name="button" type="button" class="btn btn-info js-checkremoteqiniu" value="check">测试配置（无需保存）</button>
        {if !empty($local_attachment)}
        <a name="button" class="btn btn-info one-key">一键上传</a>
        {/if}
    </div>
</div>
</div>
<!-- 七牛云 end -->

<!-- 腾讯云 start -->
<div class="remote-cos" {if empty($accountSettings['remote']['type']) || $accountSettings['remote']['type'] != '4'} style="display:none;" {/if}>
<div style="padding-left: 60px;">
    <div class="alert alert-info">
        启用腾讯云cos对象存储后，请把/attachment目录（不包括此目录）下的子文件及子目录上传至腾讯云存储, 相关工具：<br>
        <ul class="link-list">
            <p><a target="_blank" href="https://console.qcloud.com/cos/bucket" class="product-grey-font">腾讯云存储</a></p>
        </ul>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">APPID</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][cos][appid]" class="form-control" value="{$accountSettings['remote']['cos']['appid']}" placeholder=""/>
        <span class="help-block">APPID 是您商户的唯一ID</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">SecretID</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][cos][secretid]" class="form-control" value="{$accountSettings['remote']['cos']['secretid']}" placeholder=""/>
        <span class="help-block">SecretID 是您商户的安全秘钥，具有该账户完全的权限，请妥善保管</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">SecretKEY</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][cos][secretkey]" class="form-control encrypt" value="{$accountSettings['remote']['cos']['secretkey']}" placeholder=""/>
        <span class="help-block">SecretKEY 是您商户的安全秘钥，具有该账户完全的权限，请妥善保管</span>
    </div>
</div>
<div class="form-group" id="data[remote][cos]bucket">
    <label class="col-sm-2 control-label">Bucket</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][cos][bucket]" class="form-control" value="{$accountSettings['remote']['cos']['bucket']}" placeholder=""/>
        <span class="help-block">请保证bucket为可公共读取的(备注:创建存储桶时的名称，访问域名前缀)</span>
    </div>
</div>
<div class="form-group" id="data[remote][cos]_local">
    <label class="col-xs-12 col-sm-3 col-md-2 control-label">bucket所在区域</label>
    <div class="col-sm-9 col-xs-12">
        <select class="form-control" name="data[remote][cos][local]">
            <option value="" {if $accountSettings['remote']['cos']['local'] == ''}selected{/if}>无</option>
            <option value="tj" {if $accountSettings['remote']['cos']['local'] == 'tj'}selected{/if}>华北</option>
            <option value="sh" {if $accountSettings['remote']['cos']['local'] == 'sh'}selected{/if}>华东</option>
            <option value="gz" {if $accountSettings['remote']['cos']['local'] == 'gz'}selected{/if}>华南</option>
            <option value="cd" {if $accountSettings['remote']['cos']['local'] == 'cd'}selected{/if}>西南</option>
            <option value="bj" {if $accountSettings['remote']['cos']['local'] == 'bj'}selected{/if}>北京</option>
            <option value="sgp" {if $accountSettings['remote']['cos']['local'] == 'sgp'}selected{/if}>新加坡</option>
            <option value="hk" {if $accountSettings['remote']['cos']['local'] == 'hk'}selected{/if}>香港</option>
            <option value="ca" {if $accountSettings['remote']['cos']['local'] == 'ca'}selected{/if}>多伦多</option>
            <option value="ger" {if $accountSettings['remote']['cos']['local'] == 'ger'}selected{/if}>法兰克福</option>
        </select>
        <span class="help-block">选择bucket对应的区域，如果没有选择无</span>
        <span class="help-block">备注:中国香港(港澳台地区),北京(华北地区),上海(华东地区),南京(华东地区),广州(华南地区),硅谷(美国西部),成都(西南地区),重庆(西南地区),曼谷(亚太东南),雅加达(亚太东南);</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">Url</label>
    <div class="col-sm-9">
        <input type="text" name="data[remote][cos][url]" class="form-control" value="{$accountSettings['remote']['cos']['url']}" placeholder=""/>
        <span class="help-block">腾讯云支持用户自定义访问域名。注：url开头加http://或https://结尾不加 ‘/’例：http://abc.com</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label"></label>
    <div class="">
        <button name="button" type="button" class="btn btn-info js-checkremotecos" value="check">测试配置（无需保存）</button>
        {if !empty($local_attachment)}
        <a name="button" class="btn btn-info one-key">一键上传</a>
        {/if}
    </div>
</div>
</div>
<!-- 腾讯云 end -->

<div class="modal fade" id="name" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="we7-modal-dialog modal-dialog we7-form">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <div class="modal-title">上传文件</div>
            </div>
            <div class="modal-body">
                正在上传....
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    /*阿里云oss 附件存储设置 start*/
    $('.js-checkremoteoss').on('click', function () {
        let bucket = $.trim($('select[name="data[remote][alioss][bucket]"]').val());
        if (bucket == '') {
            bucket = $.trim($(':text[name="data[remote][alioss][bucket]"]').val());
        }
        let param = {
            'type': 'alioss',
            'key': $.trim($(':text[name="data[remote][alioss][key]"]').val()),
            'secret': $.trim($(':text[name="data[remote][alioss][secret]"]').val()),
            'url': $.trim($(':text[name="data[remote][alioss][url]"]').val()),
            'bucket': bucket,
            'internal': $('[name="data[remote][alioss][internal]"]:checked').val()
        };

        $.post("{$postUrl}", param, function (json) {
            let data = $.parseJSON(json);
            if (parseInt(data.status) === 1) {
                tip.msgbox.suc('配置成功');
                return false;
            }
            if (data.status < 0) {
                tip.msgbox.err(data.result.message);
                return false;
            }
        });
    });

    let aliBucket = "{$accountSettings['remote']['alioss']['bucket']}";

    let buck = function () {
        let key = $(':text[name="data[remote][alioss][key]"]').val();
        let secret = $(':text[name="data[remote][alioss][secret]"]').val();

        if (key == '' || secret == '') {
            $('#bucket').hide();
            return false;
        }

        $.post("{$postUrl}", {'type': 'buckets', 'key': key, 'secret': secret}, function (data) {
            if (parseInt(data.status) === 1) {
                $('#bucket').show();
                let bucket = $('select[name="data[remote][alioss][bucket]"]');
                bucket.empty();
                let buckets = eval(data.result.data);
                for (let i in buckets) {
                    let selected = aliBucket == buckets[i]['name'] || aliBucket == buckets[i]['name'] + '@@' + buckets[i]['location'] ? 'selected' : '';
                    bucket.append('<option value="' + buckets[i]['name'] + '@@' + buckets[i]['location'] + '"' + selected + '>' + buckets[i]['loca_name'] + '</option>');
                }
            } else {
                tip.msgbox.err('Access Key ID 或 Access Key Secret 填写错误，请重新填写。', '', 'error');
                $('#bucket').hide();
                $('select[name="data[remote][alioss][bucket]"]').val('');
                return false;
            }

        }, 'json');
    };
    buck();
    $(':text[name="data[remote][alioss][secret]"]').blur(function () {
        buck();
    });

    // 一键上传
    $('.one-key').click(function () {
        upload_remote();
        return false;
    });
    let upload_remote = function () {
        try {
            // $('#name').modal('show');
            $.post("{$postUrl}", {type: 'upload_remote','uniacid':"{$uniacid}"}, function (data) {
                console.log(data);
                // $('#name').modal('hide');

                if (parseInt(data.status) === 2) {
                    upload_remote();
                }
                if (parseInt(data.status) === 0) {
                    tip.msgbox.suc("上传完毕",location.reload());
                }
                if (parseInt(data.status) === 1) {
                    tip.msgbox.suc(data.result.message);
                }
                if (parseInt(data.status) === -1) {
                    tip.msgbox.err(data.result.message);
                }
            }, 'json');
        }catch (e) {
            console.log(e)
        }
    }
    /* 阿里云oss 附件存储设置 end */

    /*七牛云cos 附件存储设置 start*/
    $('.js-checkremoteqiniu').on('click', function(){
        let key = $.trim($(':text[name="data[remote][qiniu][accesskey]"]').val());
        if (key === '') {
            tip.msgbox.err('请填写Accesskey');
            return false;
        }
        let secret = $.trim($(':text[name="data[remote][qiniu][secretkey]"]').val());
        if (secret === '') {
            tip.msgbox.err('请填写Secretkey');
            return false;
        }
        let param = {
            'type' : 'qiniu',
            'accesskey' : key,
            'secretkey' : secret,
            'url'  : $.trim($(':text[name="data[remote][qiniu][url]"]').val()),
            'bucket' :  $.trim($(':text[name="data[remote][qiniu][bucket]"]').val())
        };

        $.post("{$postUrl}", param).done(function (json) {
            let data = $.parseJSON(json);

            if (data.status === 1) {
                tip.msgbox.suc('配置成功');
            } else {
                tip.msgbox.err(data.result.message);
            }
        }).fail(function (fail) {
            if (fail.responseJSON.code !== 200) {
                tip.msgbox.err(fail.responseJSON.msg)
            }
        }).always(function () {
            console.log("finished");
        })

    })
    /* 七牛云cos 附件存储设置 end */

    /* 腾讯云cos 附件存储设置 start */
    $('.js-checkremotecos').on('click', function(){
        let appid = $.trim($(':text[name="data[remote][cos][appid]"]').val());
        if (appid === '') {
            tip.msgbox.err('请填写APPID');
            return false;
        }
        let secretid = $.trim($(':text[name="data[remote][cos][secretid]"]').val());
        if (secretid === '') {
            tip.msgbox.err('请填写secretid');
            return false;
        }
        let secretkey = $.trim($(':text[name="data[remote][cos][secretkey]"]').val());
        if (secretkey === '') {
            tip.msgbox.err('请填写Secretkey');
            return false;
        }
        let bucket = $.trim($(':text[name="data[remote][cos][bucket]"]').val());
        if (bucket === '') {
            tip.msgbox.err('请填写bucket');
            return false;
        }
        let url = $.trim($(':text[name="data[remote][cos][url]"]').val());
        let local = $('[name="data[remote][cos][local]"]').val();
        let param = {
            'type' : 'cos',
            'appid' : appid,
            'secretid' : secretid,
            'secretkey'  : secretkey,
            'bucket' :  bucket,
            'url' : url,
            'local' : local
        };
        $.post("{$postUrl}", param).done(function (json) {
            let data = $.parseJSON(json);
            if (data.status === 1) {
                tip.msgbox.suc('配置成功');
            } else {
                tip.msgbox.err(data.result.message);
            }
        }).fail(function (fail) {
            if (fail.responseJSON.code !== 200) {
                tip.msgbox.err(fail.responseJSON.msg)
            }
        }).always(function () {
            console.log("finished");
        })
    });
    /* 腾讯云cos 附件存储设置 end */
</script>